package edu.je.prs.Controller;

import com.alibaba.fastjson.JSON;
import edu.je.prs.Mapper.StationInfoMapper;
import edu.je.prs.Model.StationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.Inet4Address;
import java.net.UnknownHostException;

/**
 * @Description:
 * @author: Anhlaidh
 * @date: 2021-03-17 11:16
 */
@RestController
public class MainController {
    @Autowired
    StationInfoMapper mapper;
    @Autowired
    StringRedisTemplate template;

    @RequestMapping(value = "QueryDetail", method = RequestMethod.GET)
    public String QueryDetail(@RequestParam(name = "id") int id) {
        StationInfo info = mapper.selectByPrimaryKey(id);
        return JSON.toJSONString(info);

    }

    @RequestMapping(value = "IncrementId", method = RequestMethod.POST)
    public String RedisTest() {
        Long id = template.opsForValue().increment("id");
        return id + "";
    }

    @RequestMapping(value = "testZuul", method = RequestMethod.GET)
    public String test() throws UnknownHostException {
        return "success"+"  this is "+ Inet4Address.getLocalHost().getHostAddress();
    }
}
